package com.ruoyi.web.controller.cat;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.cat.domain.AdGift;
import com.ruoyi.cat.service.IAdGiftService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 礼品单Controller
 * 
 * @author ruoyi
 * @date 2025-07-05
 */
@RestController
@RequestMapping("/system/gift")
public class AdGiftController extends BaseController
{
    @Autowired
    private IAdGiftService adGiftService;

    /**
     * 查询礼品单列表
     */
   // @PreAuthorize("@ss.hasPermi('system:gift:list')")
    @GetMapping("/list")
    public TableDataInfo list(AdGift adGift)
    {
        startPage();
        List<AdGift> list = adGiftService.selectAdGiftList(adGift);
        return getDataTable(list);
    }

    /**
     * 导出礼品单列表
     */
   // @PreAuthorize("@ss.hasPermi('system:gift:export')")
    @Log(title = "礼品单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AdGift adGift)
    {
        List<AdGift> list = adGiftService.selectAdGiftList(adGift);
        ExcelUtil<AdGift> util = new ExcelUtil<AdGift>(AdGift.class);
        util.exportExcel(response, list, "礼品单数据");
    }

    /**
     * 获取礼品单详细信息
     */
   // @PreAuthorize("@ss.hasPermi('system:gift:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(adGiftService.selectAdGiftById(id));
    }

    /**
     * 新增礼品单
     */
  //  @PreAuthorize("@ss.hasPermi('system:gift:add')")
  //  @Log(title = "礼品单", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult add(@RequestBody AdGift adGift)
    {
        return toAjax(adGiftService.insertAdGift(adGift));
    }

    @Log(title = "礼品单", businessType = BusinessType.UPDATE)
    @PostMapping("updateBelow")
    public AjaxResult updateBelow(@RequestBody AdGift adGift)
    {
        AdGift adGift1 =  adGiftService.selectAdGiftById(adGift.getId());
        if(adGift1 != null){
            if (adGift1.getState().equals("0")){
                adGift1.setState("1");
            }else {
                adGift1.setState("0");
            }
        }
        return success(adGiftService.updateAdGiftBy(adGift1));
    }
    /**
     * 修改礼品单
     */
  //  @PreAuthorize("@ss.hasPermi('system:gift:edit')")
    @Log(title = "礼品单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AdGift adGift)
    {
        return toAjax(adGiftService.updateAdGift(adGift));
    }

    /**
     * 删除礼品单
     */
  //  @PreAuthorize("@ss.hasPermi('system:gift:remove')")
    @Log(title = "礼品单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(adGiftService.deleteAdGiftByIds(ids));
    }
}
